package com.lsk.netdisk.file.mappers;

import com.lsk.netdisk.file.model.File;
import org.apache.ibatis.annotations.*;
import java.util.List;

@Mapper
public interface FilesMapper {
	@Select("select * from files where storagename=#{sname}")
	public File queryFileByStorageName(@Param("sname") String storageName);
	@Select("select * from files where hash=#{hash}")
	public File queryFileByHash(@Param("hash") String hash);
	@Insert("insert into files(storagename,filename,storageserver,parentdir,ownerid,hash) values(#{storageName},#{fileName},#{storageServer},#{parentDir},#{ownerId},#{hash})")
	public void doAddFile(@Param("storageName") String storageName, @Param("fileName") String fileName, @Param("storageServer") Integer storageServer, @Param("parentDir") String parentDir, @Param("ownerId") Integer ownerId, @Param("hash") String hash);
	@Delete("delete from files where id=#{id}")
	public void deleteFileById(@Param("id") Integer id);
	@Update("update set filename=#{filename} where id=#{id}")
	public void updateFileNameById(@Param("filename") String fileName, @Param("id") Integer id);
	@Select("select * from files where parentdir=#{parentdir}")
	public List<File> ls(@Param("parentdir") Integer parentDir);
	@Update("update set parentdir=#{parentdir} where id=#{id}")
	public void updateParentDirById(@Param("parentdir") String parentDir);

//	default public void addFile(File file){
//		doAddFile(file.getStorageName(),file.getFileName(),file.getStorageServer(),file.getParentDir(),file.getOwnerId(),file.getHash());
//	}
	@Insert("INSERT INTO files(storagename, storageserver, ownerid, hash, filename, parentDir) VALUES(#{storageName}, #{storageServer}, #{ownerId}, #{hash}, #{fileName}, #{parentDir})")
	public void addFile(File file);
	@Select("select * from files where id=#{id}")
	public File queryFileById(@Param("id") Integer id);
}
